package com.yonyou.exception;

import com.yonyou.model.ResultEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @author Created by Administrator on 2018-06-14.
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {


    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResultEntity handle(Exception ex) {
        log.error("出现异常：" + ex.getMessage(), ex);
        return ResultEntity.exception(-1, "网络连接错误！");
    }

    @ExceptionHandler(value = ErrorMessageException.class)
    @ResponseBody
    public ResultEntity<?> errMsgHandle(ErrorMessageException ex){
        log.error("出现抛出异常！", ex);
        return ResultEntity.exception(ex.getMessage());
    }
}
